|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
EWSUtils.java | 0% | 0% | 0% | 0% |
|
1 |
/*
|
|
2 |
* Copyright 2001-2004 The Apache Software Foundation.
|
|
3 |
*
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
6 |
* You may obtain a copy of the License at
|
|
7 |
*
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9 |
*
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13 |
* See the License for the specific language governing permissions and
|
|
14 |
* limitations under the License.
|
|
15 |
*/
|
|
16 |
|
|
17 |
package org.apache.geronimo.ews.ws4j2ee.utils;
|
|
18 |
|
|
19 |
import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationFault;
|
|
20 |
import org.apache.commons.logging.Log;
|
|
21 |
import org.apache.commons.logging.LogFactory;
|
|
22 |
import org.w3c.dom.Document;
|
|
23 |
import org.xml.sax.EntityResolver;
|
|
24 |
import org.xml.sax.InputSource;
|
|
25 |
import org.xml.sax.SAXException;
|
|
26 |
|
|
27 |
import javax.xml.parsers.DocumentBuilder;
|
|
28 |
import javax.xml.parsers.DocumentBuilderFactory;
|
|
29 |
import java.io.IOException;
|
|
30 |
import java.io.InputStream;
|
|
31 |
|
|
32 |
/**
|
|
33 |
* @author hemapani@opensource.lk
|
|
34 |
*/
|
|
35 |
public class EWSUtils { |
|
36 |
protected static Log log = |
|
37 |
LogFactory.getLog(EWSUtils.class.getName());
|
|
38 | 0 |
public static Document createDocument(InputStream in) throws GenerationFault { |
39 | 0 |
try {
|
40 | 0 |
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
41 | 0 |
dbf.setNamespaceAware(true);
|
42 | 0 |
dbf.setValidating(false);
|
43 | 0 |
dbf.setExpandEntityReferences(false);
|
44 | 0 |
DocumentBuilder db = dbf.newDocumentBuilder(); |
45 | 0 |
EntityResolver er = new EntityResolver() {
|
46 | 0 |
public InputSource resolveEntity(String publicId,
|
47 |
String systemId) |
|
48 |
throws SAXException, IOException {
|
|
49 | 0 |
InputStream is = null;
|
50 | 0 |
if ("http://java.sun.com/dtd/ejb-jar_2_0.dtd".equalsIgnoreCase(systemId)) { |
51 | 0 |
return getInputSource(EWSUtils.class.getClassLoader().getResourceAsStream("ejb-jar_2_0.dtd")); |
52 | 0 |
} else if ("http://java.sun.com/dtd/web-app_2_3.dtd".equalsIgnoreCase(systemId)) |
53 | 0 |
return getInputSource(EWSUtils.class.getClassLoader().getResourceAsStream("web-app_2_3.dtd")); |
54 | 0 |
return null; |
55 |
} |
|
56 |
|
|
57 | 0 |
private InputSource getInputSource(InputStream is) throws IOException { |
58 | 0 |
if (is == null) |
59 | 0 |
throw new IOException("error at the project set up can not find entity"); |
60 | 0 |
return new InputSource(is); |
61 |
} |
|
62 |
}; |
|
63 | 0 |
db.setEntityResolver(er); |
64 | 0 |
return db.parse(in);
|
65 |
} catch (Exception e) {
|
|
66 | 0 |
log.error(e); |
67 | 0 |
throw GenerationFault.createGenerationFault(e);
|
68 |
} |
|
69 |
} |
|
70 |
} |
|
71 |
|
|